package cn.ecut.dzy.lambda;

import org.junit.Test;

import java.util.Comparator;

/**
 * @program: JavaSEDemo
 * @description:
 * @author: DingZhenYun
 * @create: 2021-10-12 23:09
 **/

public class LambdaTest {
    @Test
    public void test1(){
        Runnable runnable=new Runnable() {
            @Override
            public void run() {
                System.out.println("我是你爹");
            }
        };
        runnable.run();
        System.out.println("--------------");
        Runnable runnable1=()->System.out.println("sb");
        runnable1.run();
    }

    @Test
    public void test2(){
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };

        int compare1 = com1.compare(12,21);
        System.out.println(compare1);
        System.out.println("***********************");
       // Lambda表达式的写法
        Comparator<Integer> com2=(o1, o2)-> Integer.compare(o1,o2);
        System.out.println(com2.compare(23,1));
        System.out.println("***********************");

        System.out.println("***********************");
        //方法引用
        Comparator<Integer> com3 = Integer :: compare;
        int compare3 = com3.compare(32,21);
        System.out.println(compare3);
    }

    @Test
    public void test3(){

    }
}
